/**
 * 
 */
package com.rpg.dragonquest.player;

import com.dalonedrau.d20.Diceroller;
import com.dalonedrau.pool.PooledStringBuilder;
import com.dalonedrau.pool.StringBuilderPool;

/**
 * @author Donald
 */
public final class DQPlayer {
	/** the one and only instance of the <code>Player</code> class. */
	private static DQPlayer	instance;
	/**
	 * Player Gives access to the singleton instance of {@link DQPlayer}.
	 * @return {@link DQPlayer}
	 */
	public static DQPlayer getInstance() {
		if (DQPlayer.instance == null) {
			DQPlayer.instance = new DQPlayer();
		}
		return DQPlayer.instance;
	}
	/** Hidden constructor. */
	private DQPlayer() { }
	/**
	 * Computes the full values for all base characteristics.
	 * @param pc the {@link DQCharacter}
	 */
	private void computeFullCharacteristics(final DQCharacter pc) {
		int strength = pc.getStrength();
		strength += pc.getModStrength();
		pc.setFullStrength(strength);

		int dexterity = pc.getDexterity();
		dexterity += pc.getModDexterity();
		pc.setFullDexterity(dexterity);

		int agility = pc.getAgility();
		agility += pc.getModAgility();
		pc.setFullAgility(agility);
		
		int endurance = pc.getEndurance();
		endurance += pc.getModEndurance();
		pc.setFullEndurance(endurance);

		int magApt = pc.getMagicAptitude();
		magApt += pc.getModMagicAptitude();
		pc.setFullMagicAptitude(magApt);

		int willpower = pc.getWillpower();
		willpower += pc.getModWillpower();
		pc.setFullWillpower(willpower);
		
		int fatigue = pc.getFatigue();
		fatigue += pc.getModFatigue();
		pc.setFullFatigue(fatigue);

		int perception = pc.getPerception();
		perception += pc.getModPerception();
		pc.setFullPerception(perception);

		int beauty = pc.getBeauty();
		beauty += pc.getModBeauty();
		pc.setFullBeauty(beauty);
	}
	private void computeSpellMods(final DQCharacter pc) {
		
	}
	/*
	public String getRankString(final DQCharacter pc) {
		PooledStringBuilder sb =
				StringBuilderPool.getInstance().getStringBuilder();
		int index = 0;
		if (pc.getRank() > 1) {
			index = pc.getRank() - 1;
		}
		if (index >= DQConsts.RANKS.length - 1) {
			index = DQConsts.RANKS.length - 1;
			sb.append(pc.getRank());
		}
		sb.append(DQConsts.RANKS[index]);
		String s = sb.toString();
		sb.returnToPool();
		return s;
	}
	*/
	private void computeEquipmentMods(final DQCharacter pc) {
		
	}
	/**
	 * Computes the full values for all base characteristics.
	 * @param pc the {@link DQCharacter}
	 */
	private void computeFullFactors(final DQCharacter pc) {
		/*
		// apply modifications based on the PC's characteristic scores
		// STRENGTH
		switch (pc.getFullStrength()) {
		case 3:
		case 4:
		case 5:
			pc.setModAttack(pc.getModAttack() - 2);
			pc.setModDefence(pc.getModDefence() - 1);
			break;
		case 6:
		case 7:
		case 8:
			pc.setModAttack(pc.getModAttack() - 1);
			break;
		case 13:
		case 14:
		case 15:
			pc.setModAttack(pc.getModAttack() + 1);
			break;
		case 16:
		case 17:
		case 18:
			pc.setModAttack(pc.getModAttack() + 2);
			pc.setModDefence(pc.getModDefence() + 1);
			break;
			default: 
				break;
		}
		// REFLEXES
		switch (pc.getFullReflexes()) {
		case 3:
		case 4:
		case 5:
			pc.setModAttack(pc.getModAttack() - 1);
			pc.setModDefence(pc.getModDefence() - 2);
			pc.setModEvasion(pc.getModEvasion() - 2);
			pc.setModStealth(pc.getModStealth() - 1);
			break;
		case 6:
		case 7:
		case 8:
			pc.setModDefence(pc.getModDefence() - 1);
			pc.setModEvasion(pc.getModEvasion() - 1);
			break;
		case 13:
		case 14:
		case 15:
			pc.setModDefence(pc.getModDefence() + 1);
			pc.setModEvasion(pc.getModEvasion() + 1);
			break;
		case 16:
		case 17:
		case 18:
			pc.setModAttack(pc.getModAttack() + 1);
			pc.setModDefence(pc.getModDefence() + 2);
			pc.setModEvasion(pc.getModEvasion() + 2);
			pc.setModStealth(pc.getModStealth() + 1);
			break;
			default: 
				break;
		}
		// INTELLIGENCE
		switch (pc.getFullIntelligence()) {
		case 3:
		case 4:
		case 5:
			pc.setModAttack(pc.getModAttack() - 1);
			pc.setModDefence(pc.getModDefence() - 1);
			pc.setModMagicalAttack(pc.getModMagicalAttack() - 1);
			pc.setModMagicalDefence(pc.getModMagicalDefence() - 1);
			break;
		case 16:
		case 17:
		case 18:
			pc.setModAttack(pc.getModAttack() + 1);
			pc.setModDefence(pc.getModDefence() + 1);
			pc.setModMagicalAttack(pc.getModMagicalAttack() + 1);
			pc.setModMagicalDefence(pc.getModMagicalDefence() + 1);
			break;
			default: 
				break;
		}
		// PSYCHIC TALENT
		switch (pc.getFullReflexes()) {
		case 3:
		case 4:
		case 5:
			pc.setModMagicalDefence(pc.getModMagicalDefence() - 2);
			pc.setModPerception(pc.getModPerception() - 1);
			break;
		case 6:
		case 7:
		case 8:
			pc.setModMagicalDefence(pc.getModMagicalDefence() - 1);
			break;
		case 13:
		case 14:
		case 15:
			pc.setModMagicalDefence(pc.getModMagicalDefence() + 1);
			pc.setModMagicalAttack(pc.getModMagicalAttack() + 1);
			break;
		case 16:
		case 17:
		case 18:
			pc.setModMagicalDefence(pc.getModMagicalDefence() + 2);
			pc.setModPerception(pc.getModPerception() + 1);
			pc.setModMagicalAttack(pc.getModMagicalAttack() + 2);
			break;
			default: 
				break;
		}
		int attack = pc.getAttack();
		attack += pc.getModAttack();
		pc.setFullAttack(attack);

		int defence = pc.getDefence();
		defence += pc.getModDefence();
		pc.setFullDefence(defence);
		
		int magicalAttack = pc.getMagicalAttack();
		magicalAttack += pc.getModMagicalAttack();
		pc.setFullMagicalAttack(magicalAttack);

		int magicalDefence = pc.getMagicalDefence();
		magicalDefence += pc.getModMagicalDefence();
		pc.setFullMagicalDefence(magicalDefence);
		
		int evasion = pc.getEvasion();
		evasion += pc.getModEvasion();
		pc.setFullEvasion(evasion);

		int stealth = pc.getStealth();
		stealth += pc.getModStealth();
		pc.setFullStealth(stealth);

		int perception = pc.getPerception();
		perception += pc.getModPerception();
		pc.setFullPerception(perception);
		*/
	}
	/**
	 * Computes the full statistics for a PC.
	 * @param pc the {@link DQCharacter}
	 */
	public void computeFullStats(final DQCharacter pc) {
		this.computeEquipmentMods(pc);
		this.computeSpellMods(pc);
		computeFullCharacteristics(pc);
		computeFullFactors(pc);
		pc.notifyWatchers();
	}
	/**
	 * Creates a "fresh" hero with no profession chosen.
	 * @return {@link DQCharacter}
	 */
	public DQCharacter getFreshHero() {
		DQCharacter pc = new DQCharacter();
		getFreshHero(pc);
		return pc;
	}
	public void getFreshHero(final DQCharacter pc) {
	}
}
